import os
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
    package_dir = get_package_share_directory('mycar_navigation2')
    map_file = os.path.join(package_dir, 'map', 'go2_map.yaml') 

    map_server_node = Node(
        package='nav2_map_server',
        executable='map_server',
        name='map_server',
        output='screen',
        parameters=[{'yaml_filename': map_file}]  
    )

    manager_mapper_node = Node(
        package='nav2_lifecycle_manager',
        executable='lifecycle_manager',
        name='lifecycle_manager_mapper',
        output='screen',
        parameters=[
            {'autostart': True},
            {'node_names': ['map_server']}
        ]  # 移除了 use_sim_time
    )

    return LaunchDescription([
        map_server_node,
        manager_mapper_node
    ])